package com.ray.controller;

import com.ray.pojo.User;
import com.ray.service.UserServiceImpl;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

public class GetAllUserController implements Controller
{
    private UserServiceImpl userServiceImpl;

    public void setUserServiceImpl(UserServiceImpl userServiceImpl)
    {
        this.userServiceImpl = userServiceImpl;
    }

    /**
     * @param request  current HTTP request
     * @param response current HTTP response
     * @return
     * @throws Exception
     */
    @Override
    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception
    {
        // 调用相应方法获得用户pojo
        List<User> allUser = userServiceImpl.getUserList();

        ModelAndView modelAndView = new ModelAndView();
        // 设置request属性
        modelAndView.addObject("alluser", allUser);

        // 转发request和response
        modelAndView.setViewName("viewAllUser");
        return modelAndView;
    }
}
